from typing import List, Optional
from sqlmodel import SQLModel, Field
from datetime import datetime
from pydantic import validator
import decimal


class DrugTracCodgItem(SQLModel):
    """药品追溯码项"""
    drugIdentificationCode: Optional[str] = Field(default=None, description="药品标识码")
    drugTracCodg: Optional[str] = Field(default=None, description="药品追溯码")
    tracCodgPacHery: Optional[int] = Field(default=None, description="包装层级")


class ShippingInfo(SQLModel):
    """收货信息模型"""
    ordNo: Optional[str] = Field(default=None, description="采购主单号")
    ordDetlCode: Optional[str] = Field(default=None, description="采购细单号")
    hisOrdNo: Optional[str] = Field(default=None, description="HIS采购主单号")
    hisUniqueKey: Optional[str] = Field(default=None, description="HIS采购细单号")
    ordDetlStas: Optional[int] = Field(default=None, description="采购细单状态")
    sbmtTime: Optional[str] = Field(default=None, description="提交时间")
    stroomID: Optional[str] = Field(default=None, description="库房ID")
    stroomName: Optional[str] = Field(default=None, description="库房名称")
    hisStroomID: Optional[str] = Field(default=None, description="HIS库房ID")
    hisStroomName: Optional[str] = Field(default=None, description="HIS库房名称")
    hisStroomAddr: Optional[str] = Field(default=None, description="HIS库房地址")
    medinsCode: Optional[str] = Field(default=None, description="医疗机构代码")
    medinsName: Optional[str] = Field(default=None, description="医疗机构名称")
    shpNo: Optional[str] = Field(default=None, description="发货主单号")
    shpDetlNo: Optional[str] = Field(default=None, description="发货细单号")
    hisDrugId: Optional[str] = Field(default=None, description="HIS药品编码")
    pubonlnProdID: Optional[str] = Field(default=None, description="省药品编码")
    ver: Optional[int] = Field(default=None, description="版本")
    drugUnino: Optional[str] = Field(default=None, description="国家药品编码")
    prodName: Optional[str] = Field(default=None, description="产品名称")
    dosform: Optional[str] = Field(default=None, description="剂型")
    spec: Optional[str] = Field(default=None, description="规格")
    pac: Optional[str] = Field(default=None, description="包装")
    pacmatl: Optional[str] = Field(default=None, description="包装材质")
    prodentpName: Optional[str] = Field(default=None, description="生产企业")
    itemname: Optional[str] = Field(default=None, description="项目名称")
    isCapacity: Optional[int] = Field(default=None, description="是否带量")
    pubonlnPric: Optional[float] = Field(default=None, description="挂网价格（元）")
    purcPrice: Optional[float] = Field(default=None, description="采购价格")
    discRate: Optional[float] = Field(default=None, description="扣点")
    hisPurcPrice: Optional[float] = Field(default=None, description="HIS采购价格")
    transformNum: Optional[float] = Field(default=None, description="转换比")
    purcAmt: Optional[float] = Field(default=None, description="采购金额")
    purcCnt: Optional[int] = Field(default=None, description="采购数")
    shpCnt: Optional[int] = Field(default=None, description="发货数")
    shpAmt: Optional[float] = Field(default=None, description="发货金额")
    shpTime: Optional[str] = Field(default=None, description="发货时间")
    shppCnt: Optional[int] = Field(default=None, description="收货数量")
    hisShppCnt: Optional[int] = Field(default=None, description="HIS收货数量")
    shppTime: Optional[str] = Field(default=None, description="收货时间")
    shpStas: Optional[int] = Field(default=None, description="发货状态")
    invono: Optional[str] = Field(default=None, description="发票号码")
    invoCode: Optional[str] = Field(default=None, description="发票代码")
    bchno: Optional[str] = Field(default=None, description="批号")
    expy: Optional[str] = Field(default=None, description="有效期")
    productionDate: Optional[str] = Field(default=None, description="生产日期")
    entpCode: Optional[str] = Field(default=None, description="配送企业编码")
    entpName: Optional[str] = Field(default=None, description="配送企业名称")
    hisEntpCode: Optional[str] = Field(default=None, description="HIS配送企业编码")
    hisEntpName: Optional[str] = Field(default=None, description="HIS配送企业名称")
    drugTracCodg: Optional[str] = Field(default=None, description="药品追溯码")
    drugTracCodgList: Optional[List[DrugTracCodgItem]] = Field(default=None, description="追溯码列表")
    incNum: Optional[int] = Field(default=None, description="自增ID")

    class Config:
        arbitrary_types_allowed = True


class ShippingInfoResponse(SQLModel):
    """收货信息响应模型"""
    returnCode: int = Field(description="返回编号")
    returnMsg: str = Field(description="返回信息")
    totalPageCount: Optional[int] = Field(default=None, description="总页数")
    totalRecordCount: Optional[int] = Field(default=None, description="总记录条数")
    currentPageNumber: Optional[int] = Field(default=None, description="当前页数")
    resultList: Optional[List[ShippingInfo]] = Field(default=None, description="结果列表")


__all__ = ["ShippingInfo", "ShippingInfoResponse", "DrugTracCodgItem"]